<?php
class pro_lap_desain_promo_model extends MY_Model {
	var $model = 'pro_lap_desain_promo_model';
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT	pro_desain_promo.*,
TO_CHAR(PRO_DESAIN_PROMO.TANGGAL_PERMINTAAN, 'DD/MM/YYYY') as tgl_perm,
					replace(pro_desain_promo.JENIS_DESAIN, '++/n', '<br>') as jenis_design_val
					FROM	 pro_desain_promo
					WHERE	UPPER(status_permintaan) = 'SUDAH DIKERJAKAN' AND
							(UPPER(kode_promosi) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(tanggal_permintaan) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(id_departemen_pk) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_departemen) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_permintaan) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_desain) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jenis_desain) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(upload_desain) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(keterangan) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'kode_promosi' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		return json_encode( $this->paging($ls_sql) );
	}
		
	function Add($arr_data){
		$this->db->insert('pro_desain_promo', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('pro_desain_promo', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_kode_promosi){
		$result = $this->db->get_where('pro_desain_promo', array('kode_promosi' => $as_kode_promosi));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_kode_promosi)
	{
		$result = $this->db->query("SELECT
			kode_promosi,
			id_departemen_pk,
			nama_departemen,
			status_permintaan,
			nama_desain,
			jenis_desain,
			upload_desain,
			keterangan, 
			TO_CHAR(PRO_DESAIN_PROMO.TANGGAL_PERMINTAAN, 'DD/MM/YYYY') as tanggal_permintaan, 
			replace(pro_desain_promo.JENIS_DESAIN, '++/n', '<br>') as jenis_design_val 
			FROM PRO_DESAIN_PROMO WHERE KODE_PROMOSI = '".$as_kode_promosi."'");
		
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM pro_desain_promo WHERE kode_promosi= '".$arr_rule['kode_promosi']."'"))<=0)
			{
				return $this->error_delete.' [id: '.$arr_rule['kode_promosi']."]<br />";
			}else{
				$this->db->delete('pro_desain_promo', array('kode_promosi' => $arr_rule['kode_promosi']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>